package fr.louloutes.lolshooter.engine.objects.protagonists;

/**
 * Class Lifebar: life bar handling
 * 
 * @author Louloute
 * 
 */
public class LifeBar
{
	int maxLife;
	int currentLife;

	/**
	 * Constructor with initialization
	 * 
	 * @param maxlife
	 */
	public LifeBar( int maxlife )
	{
		maxLife = maxlife;
		currentLife = maxlife;
	}

	/**
	 * Is the lifebar depleted ?
	 * 
	 * @return
	 */
	public boolean isEmpty()
	{
		return ( currentLife <= 0 );
	}

	/**
	 * Increment the life bar, up to its max
	 * 
	 * @param addIncrement
	 */
	public void addLife( int addIncrement )
	{
		currentLife += addIncrement;
		if ( currentLife > maxLife )
		{
			currentLife = maxLife;
		}
	}

	/**
	 * Decremetn lifebar, down to its min
	 * 
	 * @param decreaseIncrement
	 */
	public void decreaseLife( int decreaseIncrement )
	{
		currentLife -= decreaseIncrement;
		if ( currentLife < 0 )
		{
			currentLife = 0;
		}
	}

	/**
	 * Set current life to a given value
	 * 
	 * @param lifeValue
	 */
	public void setLife( int lifeValue )
	{
		currentLife = lifeValue;
		if ( lifeValue < 0 )
		{
			currentLife = 0;
		} else if ( lifeValue > maxLife )
		{
			currentLife = maxLife;
		}
	}

	/**
	 * Return the current life.
	 * 
	 * @return
	 */
	public int getLife()
	{
		return currentLife;
	}
}
